package com.ruoyi.webInfor.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.webInfor.domain.CaseInformation;
import com.ruoyi.webInfor.service.ICaseInformationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案例展示详情Controller
 * 
 * @author ruoyi
 * @date 2021-12-20
 */
@RestController
@RequestMapping("/web/caseInfor")
public class CaseInformationController extends BaseController
{
    @Autowired
    private ICaseInformationService caseInformationService;

    /**
     * 查询案例展示详情列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CaseInformation caseInformation)
    {
        startPage();
        List<CaseInformation> list = caseInformationService.selectCaseInformationList(caseInformation);
        return getDataTable(list);
    }

    /**
     * 导出案例展示详情列表
     */
    @Log(title = "案例展示详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaseInformation caseInformation)
    {
        List<CaseInformation> list = caseInformationService.selectCaseInformationList(caseInformation);
        ExcelUtil<CaseInformation> util = new ExcelUtil<CaseInformation>(CaseInformation.class);
        util.exportExcel(response, list, "案例展示详情数据");
    }

    /**
     * 获取案例展示详情详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(caseInformationService.selectCaseInformationById(id));
    }

    /**
     * 新增案例展示详情
     */
    @Log(title = "案例展示详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaseInformation caseInformation)
    {
        caseInformation.setId(IdUtils.fastSimpleUUID());
        return toAjax(caseInformationService.insertCaseInformation(caseInformation));
    }

    /**
     * 修改案例展示详情
     */
    @Log(title = "案例展示详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaseInformation caseInformation)
    {
        return toAjax(caseInformationService.updateCaseInformation(caseInformation));
    }

    /**
     * 删除案例展示详情
     */
    @Log(title = "案例展示详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(caseInformationService.deleteCaseInformationByIds(ids));
    }
}
